﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>SetRegView - 语法 &amp; 使用 | AutoHotkey v2</title>
<meta name="description" content="The SetRegView function sets the registry view used by RegRead, RegWrite, RegDelete, RegDeleteKey and Loop Reg." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>
<body>

<h1>SetRegView</h1>
<p>Sets the registry view used by RegRead, RegWrite, RegDelete, RegDeleteKey and registry loops.</p>
<pre class="Syntax"><span class="func">SetRegView</span> RegView</pre>

<h2 id="Parameters">参数</h2>
<dl>

  <dt>RegView</dt>
  <dd>
      <p>类型: <a href="../Concepts.htm#numbers">整数</a>或<a href="../Concepts.htm#strings">字符串</a></p>
      <p>Specify <strong>32</strong> to view the registry as a 32-bit application would, or <strong>64</strong> to view the registry as a 64-bit application would.</p>
      <p>Specify the word <strong>Default</strong> to restore normal behaviour.</p>
  </dd>

</dl>

<h2>General 备注</h2>
<p>This function is only useful on Windows 64-bit.  It has no effect on Windows 32-bit.</p>
<p>On 64-bit systems, 32-bit applications run on a subsystem of Windows called <a href="http://msdn.microsoft.com/en-us/library/aa384249">WOW64</a>.  By default, the system redirects certain <a href="http://msdn.microsoft.com/en-us/library/aa384253">registry keys</a> to prevent conflicts.  例如, in a 32-bit script, <code>HKLM\SOFTWARE\AutoHotkey</code> is redirected to <code>HKLM\SOFTWARE\Wow6432Node\AutoHotkey</code>.  SetRegView allows the registry functions in a 32-bit script to access redirected keys in the 64-bit registry view and vice versa.</p>

<p>The built-in variable <em>A_RegView</em> contains the current setting.  Every newly launched <a href="../misc/Threads.htm">thread</a> (such as a <a href="../Hotkeys.htm">hotkey</a>, <a href="../objects/Menu.htm">custom menu item</a>, or <a href="SetTimer.htm">timed</a> subroutine) starts off fresh with the default setting for this function. 这个默认设置可以通过在<a href="../Scripts.htm#auto">脚本启动</a>中使用此函数来改变.</p>

<h2 id="Related">相关</h2>
<p><a href="RegRead.htm">RegRead</a>, <a href="RegWrite.htm">RegWrite</a>, <a href="RegDelete.htm">RegDelete</a>, <a href="RegDeleteKey.htm">RegDeleteKey</a>, <a href="LoopReg.htm">Loop Reg</a></p>

<h2 id="Examples">示例</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a>: Shows how to set a specific registry view, and how registry redirection affects the script.</p>
<pre>
<em>; Access the registry as a 32-bit application would.</em>
SetRegView 32
RegWrite "REG_SZ", "HKLM\SOFTWARE\Test.ahk", "Value", 123

<em>; Access the registry as a 64-bit application would.</em>
SetRegView 64
value := RegRead("HKLM\SOFTWARE\Wow6432Node\Test.ahk", "Value")
RegDelete "HKLM\SOFTWARE\Wow6432Node\Test.ahk"

MsgBox "Read value '" value "' via Wow6432Node."

<em>; Restore the registry view to the default, which
; depends on whether the script is 32-bit or 64-bit.</em>
SetRegView "Default"
<em>;...</em>
</pre>
</div>

<div class="ex" id="Ex32Or64">
<p><a href="#Ex32Or64">#2</a>: Shows how to detect the type of EXE and operating system on which the script is running.</p>
<pre>if (A_PtrSize = 8)
    script_is := "64-bit"
else <em>; if (A_PtrSize = 4)</em>
    script_is := "32-bit"

if (A_Is64bitOS)
    OS_is := "64-bit"
else
    OS_is := "32-bit, which has only a single registry view"

MsgBox "This script is " script_is ", and the OS is " OS_is "."</pre>
</div>

</body>
</html>